package com.llbnk.srb.core.controller.api;


import com.llbnk.common.result.R;
import com.llbnk.srb.core.pojo.vo.BorrowerVO;
import com.llbnk.srb.core.service.BorrowerService;
import com.llbnk.srb.core.util.JwtUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 借款人 前端控制器
 * </p>
 *
 * @author llbnk
 * @since 2022-04-07
 */
@Api(tags = "借款人")
@RestController
@RequestMapping("/api/core/borrower")
@Slf4j
public class BorrowerController {

    @Resource
    private BorrowerService borrowerService;

    @ApiOperation("保存借款人信息")
    @PostMapping("/auth/save")
    //之所以是auth目录下就是要求你先登录才能保存借款人信息，你不能保存别人的信息
    public R save(@RequestBody BorrowerVO borrowerVO, HttpServletRequest request) {

        //获取当前登录人的id
        String token = request.getHeader("token");
        Long userId = JwtUtils.getUserId(token);
        borrowerService.saveBorrowerVOByUserId(borrowerVO,userId);
        return R.ok().message("信息提交成功");
    }

    /**
     * 当借款人已经保存完借款信息，应该到了提交平台审核这一步了，此时用户断掉浏览器
     * 想在登陆查看自己的信息认证进度是否审核完毕
     * 我们希望它显示的页面是“您的认证申请已成功提交，请耐心等待”
     * 而不是再次填写一边那些什么学历、收入、相关人信息、身份证照片等等
     */
    @ApiOperation("获取借款人认证状态")
    @GetMapping("/auth/getBorrowerStatus")
    public R getBorrowerStatus(HttpServletRequest request){

        String token = request.getHeader("token");
        Long userId = JwtUtils.getUserId(token);
        Integer status = borrowerService.getStatusByUserId(userId);
        return R.ok().data("borrowerStatus",status);
    }

}

